﻿namespace Dissemination.MVC.MVCContrib.Events
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using Microsoft.Practices.Unity;
    using UnityContrib.Events;

    /// <summary>
    /// Event Aggregator tokens
    /// </summary>
    public class AggregatorEventTokens : IAggregatorEventTokens
    {
        private IDictionary<string, SubscriptionToken> AggregatorTokens = new Dictionary<string, SubscriptionToken>();

        /// <summary>
        /// Gets the token.  
        /// </summary>
        /// <param name="uniqueID">The unique ID.</param>
        /// <returns>SubscriptionToken if exist, null if doesn't exist</returns>
        public SubscriptionToken GetToken(string uniqueID)
        {
            KeyValuePair<string, SubscriptionToken> token =
                AggregatorTokens.FirstOrDefault(t => t.Key == uniqueID);

            return token.Value;
        }



        /// <summary>
        /// Sets the token.
        /// </summary>
        /// <param name="uniqueID">The unique ID.</param>
        /// <param name="token">The token.</param>
        public void SetToken(string uniqueID, SubscriptionToken token)
        {
            AggregatorTokens.Add(new KeyValuePair<string, SubscriptionToken>(uniqueID, token));
        }

    }
}
